<?php
	/*==================================================================*/
	/*		文件名:admin.php                                    */
	/*		概要: 分类操作         */
	/*==================================================================*/
	class ColumnAction extends CommonAction {
		private $column;
		function __construct(){
			parent::__construct();
			$this->column=new ColumnModel();
		}
		function add($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
			
			//记住选择的操作
			if(isset($_POST["jz"])){
				$this->assign("jz", "checked");
				$this->assign("select", $this->column->buildSelect("pid", $_POST["pid"]));
			}else{
				$this->assign("select", $this->column->buildSelect("pid"));
			}

			$this->display("admin/column/add.tpl");
		}

		function insert(){
			if($this->column->validateForm()){
				if($this->column->catAdd($_POST)){
					$this->add($this->column->getMessList(),1);
				}else{
					$this->add($this->column->getMessList(),0);
				}
				
			}else{				
				$this->assign("post", $_POST);
				$this->add($this->column->getMessList(),0);

			}
		}

		function edit($tmess=null,$status=0){
			if(empty($tmess)){
				$this->assign("tmess", '提示：根栏目不能删除,可以通过重新排序改变栏目的在首页中的显示顺序,数值小的排在前面，还可以关闭部分栏目的显示.<br>注意：删除栏目时会删除该栏目下所有子栏目和图片,请慎重操作. ');
			}else{
				$this->message($status,$tmess);
			}
		
			$this->assign("list", $this->column->parseTree());
			$this->display("admin/column/edit.tpl");
		}
		function del(){
			if($this->column->remove($_GET["id"])){
				$this->edit($this->column->getMessList(),1);
			}else{
				$this->edit($this->column->getMessList(),0);
			}
		}

		function order(){
			if($this->column->order($_POST)){
				$this->edit($this->column->getMessList(),1);	
			}else{
				$this->edit($this->column->getMessList(),0);
			}
		}

		function mod($tmess=null,$status=1){
			if(empty($tmess)){
				$this->assign("tmess", '提示: 带<span class="red_font">*</span>的项目为必填信息. ');
			}else{
				$this->message($status,$tmess);
			}
		
			
			#select tab1.id,tab1.path,tab1.title,tab1.description,tab1.display,tab1.picid,tab1.ord,tab2.picName from cms_column as tab1,cms_picture as tab2 where tab1.picid=tab2.id and tab1.id=13
			$column=$this->column->find($_REQUEST["id"]);
	        pr($_REQUEST["id"]);	
			$this->assign("select", $this->column->buildSelect("pid", $this->column->getPid($column["path"])));
			$this->assign("post", $column);
			$this->assign("path", GALLERY_PATH);
		
			$this->display("admin/column/mod.tpl");
		}

		function update(){
			if($this->column->validateForm($_POST)){
				if($this->column->catMod($_POST)){
					$this->mod($this->column->getMessList(),1);
				}else{
					$this->mod($this->column->getMessList(),0);
				}
			
			}else{
				$this->mod($this->column->getMessList(),0);
			}
		}

		
		function dis(){
			$this->column->setDis($_GET["id"], $_GET["con"]);	
		}
	}
